package ar.com.gep.soccer.frontend.lazydatamodels;

import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

import ar.com.cdt.framework.core.pager.Page;

public abstract class BaseLazyDataModel<T> extends LazyDataModel<T> {

	private static final long serialVersionUID = -4171684561889851106L;

	public BaseLazyDataModel() {
		super();
	}

	protected Page getPage(int startingAt, int maxPerPage, String sortField, SortOrder sortOrder) {
		Page pager = new Page();
		pager.setPageNumber(((int) Math.ceil(startingAt / maxPerPage)) + 1);
		pager.setPageSize(maxPerPage);
		pager.setSortColumn(sortField);
		if (sortField != null) {
			if (sortOrder == SortOrder.ASCENDING) {
				pager.setOrderType(1);
			} else {
				pager.setOrderType(2);
			}
		}
		setPageSize(maxPerPage);
		return pager;
	}

}
